package com.gogant.spider.core;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;

public class Request {
    private URL url;
    private Map<String, String> headers;

    public Request(URL url) {
        if (url == null) {
            throw new IllegalArgumentException("URL can not be null");
        }
        this.url = url;
        this.headers = new HashMap<String, String>();
    }

    /**
     * 获取URL
     *
     * @return
     */
    public final URL getURL() {
        return url;
    }

    /**
     * 设置请求头
     *
     * @param key
     * @param value
     */
    public final void putHeader(String key, String value) {
        headers.put(key, value);
    }

    /**
     * 获取请求头
     *
     * @param key
     * @return
     */
    public final String getHeader(String key) {
        return headers.get(key);
    }

    /**
     * 移除请求属性
     *
     * @param key
     * @return
     */
    public final String removeHeader(String key) {
        return headers.remove(key);
    }

    /**
     * 获取所有请求头属性
     *
     * @return
     */
    public final Map<String, String> getHeaders() {
        return headers;
    }

}
